package com.hucheng.order.entity;

import com.hucheng.order.dto.GoodsDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 持久层数据
 **/
@Data
public class GoodsDO {
    private Integer goodsId;
    private String goodsName;
    private String goodsTitle;
    private String goodsImg;
    private String goodsDetail;
    private String goodsPrice;
    private String goodsStock;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static GoodsDO buildGoodsDO(final GoodsDTO goodsDTO) {
        if (goodsDTO != null) {
            GoodsDO goodsDO = new GoodsDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(goodsDTO.getGoodsId()+"")) {
                goodsDO.setGoodsId(goodsDTO.getGoodsId());
                goodsDO.setDateCreated(currentTime);
            }else{
                goodsDO.setDateUpdated(currentTime);
            }
            goodsDO.setGoodsName(goodsDTO.getGoodsName());
            goodsDO.setGoodsTitle(goodsDTO.getGoodsTitle());
            goodsDO.setGoodsImg(goodsDTO.getGoodsImg());
            goodsDO.setGoodsDetail(goodsDTO.getGoodsDetail());
            goodsDO.setGoodsPrice(goodsDTO.getGoodsPrice());
            goodsDO.setGoodsStock(goodsDTO.getGoodsStock());
            return goodsDO;
        }
        return null;
    }
}
